import Packet from "../net/Packet"

// 角色
export default class Role {
	/**
	 * @param rid ID
	 * @param name 名字
	 * @param sex 性别
	 * @param lev 等级
	 */
	public constructor(public rid: Long, public name: string, public sex: number, public lev: number) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(3900)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): Role {
		const rid = packet.ReadUlong()
		const name = packet.ReadString()
		const sex = packet.ReadByte()
		const lev = packet.ReadUshort()
		return new Role(rid, name, sex, lev)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteUlong(this.rid)
		packet.WriteString(this.name)
		packet.WriteByte(this.sex)
		packet.WriteUshort(this.lev)
		return packet
	}
}
